/** * 债转确认*/
<template>
  <Card style="height:800px">
    <header>
      <span style="vertical-align:middle">申请书编号:</span>
      <Input v-model="loanId" style="width:200px" placeholder="请输入"></Input>
      <Button type="primary" @click="queryPage" style="margin-left: 10px;">查询</Button>
    </header>

    <Content style="margin-top:20px;">
      <Table border :columns="debtListCols" :data="debtListData"></Table>
    </Content>
    <div class="page-box">
      <Page :total="totalNumber" size="small" :current="currentPage" :page-size="pageSize" show-total @on-change="pageIndexChange"></Page>
    </div>
  </Card>
</template>

<script>
export default {
  data () {
    return {
      $ajax: null,
      name: null,
      desc: '',
      path: this.$route.path,
      totalNumber: 0,
      currentPage: 1,
      pageSize: 10,
      debtListCols: [
        {
          title: 'ID',
          key: 'id',
          align: 'center',
          width: 100,
          type: 'index'
        },
        {
          title: '申请书编号',
          align: 'center',
          width: 200,
          key: 'loanId'
        },
        {
          title: '资金方',
          align: 'center',
          key: 'fundCode'
        },
        {
          title: '是否债转',
          align: 'center',
          key: 'debtFlag',
          render: function (h, param) {
            const debtFlag = param.row.debtFlag
            switch (debtFlag) {
              case 0:
                return h('div', '未债转')
              case 1:
                return h('div', '已债转')
              default:
                return h('div', '')
            }
          }
        },
        {
          title: '是否确认',
          align: 'center',
          key: 'isAffirm',
          render: function (h, param) {
            const isAffirm = param.row.isAffirm
            switch (isAffirm) {
              case 0:
                return h('div', '未确认')
              case 1:
                return h('div', '已确认')
              default:
                return h('div', '')
            }
          }
        },
        {
          title: '转让日期',
          align: 'center',
          key: 'tranDate'
        },
        {
          title: '转让方',
          align: 'center',
          key: 'transferor'
        },
        {
          title: '受让方',
          align: 'center',
          key: 'transferee'
        },
        {
          title: '转让价格',
          align: 'center',
          key: 'tranPrice'
        },
        {
          title: '操作',
          align: 'center',
          width: 150,
          render: function (h, param) {
            const vm = this
            return h('div', {}, [
              (param.row.debtFlag === 1 && param.row.isAffirm === 0) && h('Button', {
                props: {
                  type: 'primary',
                  size: 'small'
                },
                style: {
                  fontSize: '12px',
                  marginLeft: '5px'
                },
                on: {
                  click: () => {
                    this.$Modal.confirm({
                      title: '确认债权转让',

                      content: '通过?',

                      okText: '确定',

                      cancelText: '取消',
                      onOk: () => {
                        var params = {
                          loanId: param.row.loanId,
                          fundCode: param.row.fundCode,
                          isAffirm: 1
                        }
                        vm.$ajax.post(vm.$appContext.marvels_core_financial +
                          'financial/fund/debt/service/submitDebtConfirm', params).then(re => {
                          var data = re.data.data
                          var code = data.code
                          if (code === 'success') {
                            vm.$Message.success('操作成功!')
                            param.row.isAffirm = 1
                          } else {
                            vm.$Message.warning('操作失败!')
                          }
                          // this.$Message.success(data)
                          // } else {
                          // this.$Message.warning(data)
                          // }
                          // this.queryPage()
                        }).catch(er => {

                        })
                      }
                    })
                  }

                }
              }, '确认')
            ])
          }.bind(this)
        }
      ],
      debtListData: []
    }
  },

  methods: {
    pageIndexChange (pageIndex) {
      this.currentPage = pageIndex
      this.queryPage()
    },
    initPage () {
      this.queryPage()
    },
    queryPage () {
      let vm = this
      let params = {}
      params.loanId = vm.loanId
      params.pageSize = 10
      this.$ajax.post(this.$appContext.marvels_core_financal +
        'financial/fund/debt/service/getDebtlist', params).then(re => {
        if (re.data.code === 'success') {
          vm.$Message.success('操作成功!')
          vm.debtListData = re.data.data.list
          vm.totalNumber = re.data.data.pages
        } else {
          vm.$Message.warning(re.data.message)
        }
      }).catch(er => {
        vm.$Message.error('操作失败')
      })
    }
  },

  created () {
    // 初始化当前页面请求对象实例
    this.$ajax = this.$util.ajax()
    this.initPage()
  }
}
</script>

<style lang="less">
@import '../../../styles/common.less';
@import '../../../styles/table.less';
</style>
